package com.davfx.httpnio;

import java.nio.channels.Selector;

final class Listener {
	
	private final Worker worker;
	
	public Listener(Worker worker) {
		this.worker = worker;
	}
	
	public Listening listen(final String host, final int port) {
		final BasicListening listening = new BasicListening(worker);
		worker.add(new SelectorVisitor() {
			@Override
			public void visit(final Selector selector) {
				if (listening.isClosed()) {
					return;
				}
				listening.create(selector, host, port);
			}
		});
		return listening;
	}
}
